package com.swensen.game.editor.data;

import com.swensen.game.data.BoardData;
import com.swensen.game.data.Tile;

public class EditorBoardData extends BoardData {
	
	public EditorBoardData(String tileSetPath) {
		super(tileSetPath);
	}

	/** The current tile. */
	private int currentTile = -1;
	
	private int level = 1;
	
	public int getLevel() {
		return level;
	}
	
	public void setLevel(int l) {
		level = Math.max(0, Math.min(l, 3));
	}
	
	/**
	 * Gets the current tile.
	 *
	 * @return the current tile
	 */
	public Tile getCurrentTile() {
		if (currentTile == -1) {
			return null;
		}
		return tileSet.getTiles().get(currentTile);
	}

	/**
	 * Gets the current tile number.
	 *
	 * @return the current tile number
	 */
	public int getCurrentTileNumber() {
		return currentTile;
	}
	
	/**
	 * Move current tile.
	 *
	 * @param dtile the dtile
	 */
	public void moveCurrentTile(int dtile) {
		currentTile += dtile;
		int tileCount = tileSet.getTiles().size() + 1;
		if (currentTile < -1) {
			currentTile += ((Math.abs(currentTile) / (tileCount)) + 1) * tileCount;
		}
		else if(currentTile >= tileCount - 1) {
			currentTile = currentTile % tileCount;
			if (currentTile == tileCount - 1) {
				currentTile = -1;
			}
		}
	}

	/**
	 * Sets the current tile.
	 *
	 * @param i the new current tile
	 */
	public void setCurrentTile(int i) {
		currentTile = Math.max(-1, Math.min(tileSet.getTiles().size() - 1, i));
	}
}
